﻿using System;
using System.Threading.Tasks;

namespace Chapter1_11
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Task<int> T = Task.Run(() =>
            {
                return 42;
            });
            
            T.ContinueWith((i) => {
                Console.WriteLine("Task cancelada");
            }, TaskContinuationOptions.OnlyOnCanceled);

            T.ContinueWith((i) => {
                Console.WriteLine("Task encerrada com falha");
            }, TaskContinuationOptions.OnlyOnFaulted);

            Task complete = T.ContinueWith((i) => {
                Console.WriteLine("completo com valor {0}", i.Result);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            complete.Wait();
            Console.ReadLine();
        }
    }
}
